<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>3-05 垂直对齐方式</title>
</head>
<body>
  <canvas id="c" width="800" height="300" style="border: 1px solid #ccc;"></canvas>

  <script>
    const context = document.getElementById('c')
    const ctx = context.getContext('2d')

    // 横向的辅助线（参考线，在画布中间）
    ctx.moveTo(0, 150)
    ctx.lineTo(800, 150)
    ctx.strokeStyle = 'red'
    ctx.stroke()

    ctx.font = '20px Arial'

    // 默认 alphabetic
    ctx.textBaseline = 'alphabetic'
    ctx.fillText('雷猴 alphabetic', 10, 150)

    // 默认 top
    ctx.textBaseline = 'top'
    ctx.fillText('雷猴 top', 200, 150)

    // 默认 bottom
    ctx.textBaseline = 'bottom'
    ctx.fillText('雷猴 bottom', 320, 150)

    // 默认 middle
    ctx.textBaseline = 'middle'
    ctx.fillText('雷猴 middle', 480, 150)

    // 默认 hanging
    ctx.textBaseline = 'hanging'
    ctx.fillText('雷猴 hanging', 640, 150)
  </script>
</body>
</html>